<?php

namespace App\Service\ChatGroup;

use AlibabaCloud\Client\Request\Request;
use App\Http\Controllers\BaseController;
use App\Models\ChatGroup\ChatGroupSessionModel;
use FontLib\Table\Type\maxp;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CustomerServeService extends BaseController
{
    /**
     * 获取左侧群列表
     *
     * @param int $userId
     * @param int $pageSize
     * @param int $pageNum
     * @param array $shopIds
     * @param int $shopStatus
     * @param int $serveIn
     * @param string $content
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function getGroupList(
        int $userId = 0,
        int $pageSize = 10,
        int $pageNum = 0,
        array $shopIds = [],
        int $shopStatus = -1,
        int $serveIn = -1,
        string $content = '',
        int $shopCode = 0
    ): array {
        $permissionLists = getRmsUserPermissionList([], 'chatgroup');
        $serveInList     = [
            ChatGroupSessionModel::SERVE_IN_YES,
            ChatGroupSessionModel::SERVE_IN_ING,
            ChatGroupSessionModel::SERVE_IN_NO,
        ];

        $chatGroupSessionModel = new ChatGroupSessionModel();
        foreach ($serveInList as $item) {
            $serveData[$item] = $chatGroupSessionModel->getGroupLists(
                $userId,
                $pageSize,
                $pageNum,
                $shopIds,
                $shopStatus,
                $item,
                $permissionLists,
                $content,
                $shopCode
            );
        }

        if ($serveIn == -1) {
            $serveIn = ChatGroupSessionModel::SERVE_IN_NO;
        }

        $result = $serveData[$serveIn];

        $tabs = [];
        foreach ($serveData as $datumKey => $datum) {
            $tabs['tabs'][] = [
                'tabName' => ChatGroupSessionModel::SERVE_IN_GROUP_TEXT[$datumKey],
                'count'   => $datum['count'],
                'serveIn' => $datumKey
            ];
        }

        return $result + $tabs;
    }

}
